<template>
    <rx-layout>
        <div slot="center" style>
            <rx-fit>
                <div slot="toolheader" foldheader="true" foldbtn="false" border="false">
                    <div class="table-operator">
                        <rx-button alias="formStampAdd" :butn-icon="'plus'" :butn-type="'primary'" :show-no-right="true"
                                   @click="add">{{ $ti18('rxList.newBtn', '新建') }}
                        </rx-button>
                        <a-dropdown
                            v-if="editEnable && selectedRowKeys.length > 0 || removeEnable && selectedRowKeys.length > 0">
                            <a-button style="margin-left: 8px"> {{ $ti18('rxList.moreBtn', '更多') }}
                                <a-icon type="down"/>
                            </a-button>
                            <a-menu slot="overlay">
                                <a-menu-item key="1" v-if="editEnable && selectedRowKeys.length > 0"
                                             alias="formStampEdit" :butn-icon="'edit'"
                                             :butn-type="'primary'" :show-no-right="false" @click="editOne">
                                    <a-icon type="edit"/>
                                    {{ $ti18('rxList.editBtn', '编辑') }}
                                </a-menu-item>
                                <a-menu-item key="2" v-if="removeEnable && selectedRowKeys.length > 0"
                                             alias="formStampDelete" :butn-icon="'delete'" :butn-type="'danger'"
                                             :show-no-right="false" @click="delByIds(selectedRowKeys)">
                                    <a-icon type="delete"/>
                                    {{ $ti18('rxList.delBtn', '删除') }}
                                </a-menu-item>
                            </a-menu>
                        </a-dropdown>
                    </div>
                    <span class="search-btn-box">
                        <span class="search-btn" @click="searchshow"><i
                        class="iconfont iconguolv"></i>{{ $ti18('rxList.leachBtn', '过滤') }}</span>
                    </span>
                </div>
                <div slot="searchbar" btnalign="right" v-if="fitSearch" @search="search" @cancel="cancel"
                     @close="close">
                    <a-form layout="vertical">
                        <a-form-item :label="i18n('form.name','名字')">
                            <a-input :placeholder="i18n('form.name','名字','input')" v-model="queryParam.Q_NAME__S_LK"/>
                        </a-form-item>
                    </a-form>
                </div>
                <rx-grid
                    ref="table"
                    :allowRowSelect="true"
                    :multiSelect="true"
                    :bordered="isBorder"
                    :columns="columns"
                    :defaultPageSize="10"
                    url="/api-form/form/core/formStamp/query"
                    :queryParam="queryParam"
                    data-field="result.data"
                    :pageSizeOptions="['10','30','40']"
                    id-field="id"
                    @selectChange="onSelectChange"
                >
                    <span slot="action" slot-scope="{ text, record }" class="actionIcons">
                     <span @click="edit(record)">{{ $ti18('rxList.editBtn', '编辑') }}</span>
                     <span @click="delByIds([record.id])">{{ $ti18('rxList.delBtn', '删除') }}</span>
                     <span @click="editPermission(record.id)"
                           :title="i18n('list.authorize','授权')">{{ i18n('list.authorize', '授权') }}</span>
                    </span>
                </rx-grid>
            </rx-fit>
        </div>
    </rx-layout>
</template>

<script>
import FormStampApi from '@/api/form/core/formStamp'
import FormStampEdit from './FormStampEdit'
import {BaseList, RxFit, RxGrid, Util} from "@lowcode/jpaas-common-lib";
import PermissionDialog from "@/views/modules/share/PermissionDialog";
import FormStampAuthApi from "@/api/form/core/formStampAuth";

export default {
    name: 'FormStampList',
    mixins: [BaseList],
    components: {
        RxFit
    },
    data() {
        return {
            columns: [
                {
                    title: this.$ti18('rxList.index', '序号'),
                    type: 'indexColumn',
                    width: 40,
                    dataIndex: 'serial',
                    scopedSlots: {customRender: 'serial'}
                },
                {title: this.i18n('form.name', '名字'), dataIndex: 'name', width: 100},
                {title: this.$ti18('rxForm.notes', '备注'), dataIndex: 'comment', width: 140},
                {
                    title: this.$ti18('rxForm.createTime', '创建时间'),
                    dataIndex: 'createTime',
                    sorter: true,
                    sortField: 'CREATE_TIME_',
                    width: 140
                },
                {
                    title: this.$ti18('rxList.action', '操作'),
                    width: 60,
                    dataIndex: 'action',
                    scopedSlots: {customRender: 'action'}
                }
            ],
            component: FormStampEdit,
            comment: this.i18n('list.sealManage', '印章管理'),
            widthHeight: ['800px', '600px'],
            fitSearch: false,
        }
    },
    methods: {
        i18n(name, text, key) {
            return this.$ti18(name, text, "formStamp", key);
        },
        delById(ids) {
            return FormStampApi.del({ids: ids.join(',')});
        },
        getListByParams(parameter) {
            return FormStampApi.query(parameter)
        },

        async editPermission(objectId) {
            let permission = {type: "ALL", typeList: []};
            let data = await FormStampAuthApi.getPermissionByObjectId(objectId);
            if (data.success) {
                permission = data.data;
            }
            var conf = {
                component: PermissionDialog,
                title: this.i18n('list.portalDesign', '权限设计'),
                widthHeight: ['850px', '500px'],
            };
            var self_ = this;
            var baseConf = {
                curVm: self_,
                data: {
                    permission: permission,
                }
            }
            let config = Object.assign(baseConf, conf);

            Util.open(config, function (action, data) {
                if (action != "ok") {
                    return;
                }
                var params = {
                    objectId: objectId,
                    type: data.type
                };
                if ("custom" == data.type) {
                    params.typeList = data.typeList;
                }
                FormStampAuthApi.savePermission(params);
            })
        },

    }
}
</script>
<style scoped>
.table-operator {
    padding: 4px;
}

.table-operator button {
    margin: 2px;
}
</style>

